package com.jianda.view.windows;

import com.jianda.view.ButtonView;
import com.jianda.view.TextView;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * 编辑SerialPort参数的窗口
 */
public class EditSerialPortWindows extends JFrame implements ActionListener {

    JFrame frame;

    private static EditSerialPortWindows editSerialPortWindows;

    /*public static EditSerialPortWindows getInstance() {
        if (editSerialPortWindows == null) {
            synchronized (EditSerialPortWindows.class) {
                if (editSerialPortWindows == null) {
                    editSerialPortWindows = new EditSerialPortWindows(Mainwindows.getInstance());
                }
            }
        }
        return editSerialPortWindows;
    }*/

    public EditSerialPortWindows(final JFrame frame) {
        setTitle("设置串口参数");
        setLayout(null);
        setAlwaysOnTop(true);
        setBounds(
                new Rectangle(
                        (int)Math.abs(frame.getBounds().getX() * 83.33),
                        (int)Math.abs(frame.getBounds().getY() * 10.111),
                        (int) Math.abs(frame.getBounds().getWidth() * 0.198),
                        (int)Math.abs(frame.getBounds().getHeight() * 0.341)
                )
        );
        // 文本配置
        TextView.editTextSerial(this);

        // 按钮配置
        ButtonView.editTextSerial(this);

        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                // 设置启用
                frame.setEnabled(true);
                System.out.println("设置启用成功");
            }
        });

        setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {

    }
}
